s = 'XIV'; //14
var romanToInt = function (s) {
    var sum = 0;
    var obj = {
        I: 1,
        V: 5,
        X: 10,
        L: 50,
        C: 100,
        D: 500,
        M: 1000
    }
    var roman = s.split('');

    for (var i = 0; i < roman.length - 1; i++) {
        if (obj[roman[i + 1]] <= obj[roman[i]]) {
            sum = sum + obj[roman[i]];
        } else {
            sum = sum - obj[roman[i]];
        }
    }
    return sum + obj[roman[roman.length - 1]];
}


console.log(romanToInt(s));

